package com.mall.service.eshop;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.eshop.EshopBannerService;
import com.mall.custom.dao.read.EshopBannerReadMapper;
import com.mall.custom.dao.write.EshopBannerWriteMapper;
import com.mall.pojo.EshopBanner;
import com.mall.pojo.EshopBannerExample;
import com.mall.pojo.EshopBannerExample.Criteria;
import com.mall.query.Page;

@Service
public class EshopBannerServiceImpl implements EshopBannerService {
	
	@Autowired
	private EshopBannerWriteMapper eshopBannerWriteMapper;
	@Autowired
	private EshopBannerReadMapper eshopBannerReadMapper;

	@Override
	public int insertEshopBannerByPrimaryKey(EshopBanner eshopBanner) {
		return	this.eshopBannerWriteMapper.insert(eshopBanner);
		
	}

	@Override
	public List<EshopBanner> getEshopBannerListByExample(EshopBannerExample example) {
		
		return this.eshopBannerReadMapper.selectByExample(example);
	}

	@Override
	public Integer modifyEshopBannerByPrimaryKey(EshopBanner eshopBanner) {
		return this.eshopBannerWriteMapper.updateByPrimaryKey(eshopBanner);
	}

	@Override
	public List<EshopBanner> getEshopBannerListByPageAndStatus(Page page, Integer status,Integer type) {
		if(page == null){
			page = new Page();
			page.setPageByPageNoAndPageSize(1, 10);
		}
		EshopBannerExample example = new EshopBannerExample();
		example.setOrderByClause("gmt_modify desc");
		example.setLimit(page.getLength());
		example.setStart(page.getBegin());
		Criteria criteria = example.createCriteria();
		if(status != null){
			criteria.andStatusEqualTo(status);
		}
		if(type != null){
			criteria.andTypeEqualTo(type);
		}
		criteria.andStatusNotEqualTo(-8);
		List<EshopBanner> eshopBannerList = this.eshopBannerReadMapper.selectByExample(example);
		return eshopBannerList;
	}

	@Override
	public EshopBanner getEshopBannerById(Long eshopBannerId) {
		return this.eshopBannerReadMapper.selectByPrimaryKey(eshopBannerId);
	}

	@Override
	public Integer getEshopBannerCountByStatusAndType(Integer status, Integer type) {
		EshopBannerExample example = new EshopBannerExample();
		example.setOrderByClause("gmt_modify desc");
		
		Criteria criteria = example.createCriteria();
		if(status != null){
			criteria.andStatusEqualTo(status);
		}
		if(type != null){
			criteria.andTypeEqualTo(type);
		}
		criteria.andStatusNotEqualTo(-8);
		
		return this.eshopBannerReadMapper.countByExample(example);
	}


}
